﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using ENT.GP.Datos.MysqlHelper;

namespace ENT.GP.Core.Core
{
    public static class Util
    {
        public static void RegistarLog(object error)
        {
            try
            {

                error = string.Format("{0}{0}--------{2} : {3}--------{0}{1}{0}",Environment.NewLine,error,DateTime.Now.ToLongDateString(),DateTime.Now.ToLongTimeString());
                System.Text.Encoding encod = System.Text.Encoding.UTF8;
                System.IO.FileStream log = System.IO.File.Open(ConfigurationManager.AppSettings.Get("PathLog"), System.IO.FileMode.Append);
                log.Write(encod.GetBytes(error.ToString()), 0, encod.GetByteCount(error.ToString()));
                log.Close();
            }
            catch (Exception ex)
            {
                try
                {
                    var log = Log.NewLog();
                    log.InfoLog =
                        string.Format("Error de Log de la aplicación{0}{1}Información de controlador del Log {2}", error, Environment.NewLine, ex.ToString());
                    log.Save();
                }
                catch
                {
                }
            }
        }
        public static DataSet EjecutarConsulta(string consulta)
        {
            return HelperMySql.ObtenerConexion("").EjecutarStoreProcedure(consulta);
        }
        public static DataSet EjecutarSPGenerico(string nombreSP,List<Param> p)
        {
            HelperMySql objhm = HelperMySql.ObtenerConexion("");
            if (p.Count>0)
            {
                MySql.Data.MySqlClient.MySqlParameter[] parametros = new MySql.Data.MySqlClient.MySqlParameter[p.Count];
                int np=0;
                foreach (var par in p)
                {
                    parametros[np] = new MySql.Data.MySqlClient.MySqlParameter(par.Parametro,par.Valor);
                    np++;
                }
                return objhm.EjecutarStoreProcedure(parametros, nombreSP);
            }
            else
                return objhm.EjecutarStoreProcedure(null, nombreSP);
            
            
        }
        
       
    }
    public class Alertas
    {
        public int RegistrarAlerta()
        {
            int res = 0;

            return res;
        }

    }
    public class Param
	{
		public object Valor { get; set; }
        public string Parametro { get; set; }
	}
}
